﻿Imports System.Runtime.CompilerServices

Module ControlExtensions

    <Extension()> _
    Public Sub CenterRespectParent(ByVal control As Control)

        Dim parent As Control = control.Parent

        If (parent Is Nothing) Then
            Return
        End If

        Dim x = CInt(Math.Round((parent.Width / 2) - (control.Width / 2), 0))
        Dim y = CInt(Math.Round((parent.Height / 2) - (control.Height / 2), 0))

        control.Location = New Point(x, y)

    End Sub

End Module
